package domain;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class LeerlingLezer {
	private School school;
	
	public LeerlingLezer(School school){
		setSchool(school);
	}

	public School getSchool() {
		return school;
	}

	private void setSchool(School school) {
		this.school = school;
	}
	
	public void lees(String filepath) throws DomainException{
		File f = new File(filepath);
		try {
			Scanner fs = new Scanner(f);
			while(fs.hasNextLine()){
				String lijn = fs.nextLine();
				Scanner ls = new Scanner(lijn);
				ls.useDelimiter(";");
				String voornaam = ls.next();
				String achternaam = ls.next();
				String straatnaam = ls.next();
				String huisnummer = ls.next();
				String postcode = ls.next();
				String stad = ls.next();
				Leerling leerling = new Leerling(voornaam, achternaam, straatnaam, huisnummer, postcode, stad);
				boolean hasQR = false;
				if(ls.hasNext()){
					hasQR = ls.nextBoolean();					
				}
				leerling.setQrCodeGegenereerd(hasQR);
				getSchool().voegToe(leerling);				
				ls.close();
			}			
			fs.close();
		} catch (FileNotFoundException e) {
			throw new DomainException("kan bestand niet vinden", e);
		}
		
	}

}
